home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_11 / 2n11075a < prev    next >
Text File  |  1991-09-29  |  24KB  |  705 lines

  1. //  VCR.CPP - VCR device driver class.
  2. //      VCR::VCR - Constructor for VCR
  3. //      VCR::~VCR - Destructor for VCR
  4. //      VCR::SendCommand - Send command string to VCR
  5. //      VCR::Stop - Puts the VCR into Stop mode.
  6. //      VCR::Eject - Causes the tape to be ejected from the VCR.
  7. //      VCR::Rewind - Places the VCR into full speed rewind.
  8. //      VCR::FastForward - Places the VCR into full speed fast forward.
  9. //      VCR::PlayFastReverse - Places the VCR into fast reverse play.
  10. //      VCR::PlayFastForward - Places the VCR into fast forward play.
  11. //      VCR::Still - Causes the VCR to Still on the current frame.
  12. //      VCR::Record - Begin recording mode.
  13. //      VCR::Play - Begins normal play mode.
  14. //      VCR::ReversePlay - Begins normal reverse play mode;
  15. //      VCR::StepForward - From a still frame, advance to next field.
  16. //      VCR::StepReverse - From a still frame, step to previous field.
  17. //      VCR::PowerToggle - Toggle VCR power.
  18. //      VCR::ValidateFrame - Adjust frame format to ensure validity
  19. //      VCR::ReceiveResponse - Receive VCR response to request
  20. //      VCR::ShuttleOn - Enables jog/shuttle mode
  21. //      VCR::ShuttleUp - Increase shuttle speed
  22. //      VCR::ShuttleDown - Decrease shuttle speed
  23. //      VCR::ForwardShuttle - Forward shuttle
  24. //      VCR::ReverseShuttle - Reverse Shuttle
  25. //      VCR::CueToFrame - Cue to frame
  26. //      VCR::SetCueType - Set cue type
  27. //      VCR::PlayToFrame - Play to frame
  28. //      VCR::PlaySegment - Play segment
  29. //      VCR:AudioInsertToFrame - Audio insert to frame
  30. //      VCR::AudioVideoInsertToFrame - Audio/Video insert to frame
  31. //      VCR::Preplay - Preroll play
  32. //      VCR::Calibrate - Calibrate
  33. //      VCR::ClearCounter - Clear frame count
  34. //      VCR::AudioSelect - Audio select
  35. //      VCR::ResetVCR - Perform VCR reset
  36. //      VCR::RequestFrame - Request current frame count
  37. //      VCR::RequestMode - Request current VCR mode
  38.  
  39. #include    <stdio.h>
  40.  
  41. #include    "VCR.h"
  42.  
  43.  
  44. /******************************************************************
  45. *   VCR::ReceiveResponse - Receive VCR response to command
  46. *
  47. *
  48. *   Class Variables Used:
  49. *       Port *SerialPort
  50. *
  51. *   Returns:
  52. *       Str sResponse
  53. *
  54. *   Copyright:
  55. *       Original code by William H. Roetzheim (619) 669-6970
  56. *       Copyright (c) 1991 by William H. Roetzheim
  57. *       All rights reserved.
  58. **********************************************************************/
  59. Str VCR::ReceiveResponse (void)
  60.  
  61. {
  62.     int     i = 0;
  63.     char    szBuffer [21];
  64.  
  65.     // wait for start of command string
  66.     while (i != 0x02) i = spSerialPort->InChar();
  67.  
  68.     // Receive actual response
  69.     int nBufferIndex = 0;
  70.     i = spSerialPort->InChar ();
  71.     while (i != 0x03)
  72.     {
  73.         szBuffer [nBufferIndex++] = i;
  74.         i = spSerialPort->InChar ();
  75.     }
  76.     szBuffer [nBufferIndex] = 0;
  77.     return (Str) szBuffer;
  78. }
  79.  
  80.  
  81.  
  82. /******************************************************************
  83. *   VCR::ValidateFrame - Adjust frame fields to ensure validity
  84. *
  85. *   Parameters:
  86. *       struct Frame& sfFrame (in/out) - frame to be adjusted.
  87. *
  88. **********************************************************************/
  89. void    VCR::ValidateFrame (struct Frame& sfFrame)
  90. {
  91.     // If out of range, attempt to bring into range
  92.     if (sfFrame.nFrame < 0) sfFrame.nFrame = 0;
  93.     sfFrame.nSecond += (sfFrame.nFrame / 30);
  94.     sfFrame.nFrame %= 30;
  95.     if (sfFrame.nSecond < 0) sfFrame.nSecond = 0;
  96.     sfFrame.nMinute += (sfFrame.nSecond / 60);
  97.     sfFrame.nSecond %= 60;
  98.     if (sfFrame.nMinute < 0) sfFrame.nMinute = 0;
  99.     sfFrame.nHour += (sfFrame.nMinute / 60);
  100.     sfFrame.nMinute %= 60;
  101.     if (sfFrame.nHour < 0) sfFrame.nHour = 0;
  102.     if (sfFrame.nHour > 9) sfFrame.nHour = 9;
  103. }
  104.  
  105.  
  106.  
  107. /******************************************************************
  108. *   VCR::ShuttleOn - Enables jog/shuttle mode
  109. *
  110. *   Notes:
  111. *       1.  When received, the VCR enters the shuttle mode.  This
  112. *           enables the shuttle up/down commands and the field
  113. *           step commands.
  114. *
  115. *       2.  The VCR responds to this command by Still framing at
  116. *           the current tape position.
  117. *
  118. *       3.  Executing Still or Stop commands will terminate this
  119. *           mode.
  120. *
  121.  
  122. *       4.  Command duration is 300 mSec.  Up to 1 seconds may be
  123. *           required for the VCR to obtain a clean still frame.
  124. *
  125. *       5.  Audio is muted, video playback is output.
  126. *
  127. **********************************************************************/
  128. void VCR::ShuttleOn (void)
  129. {
  130.     SendCommand ("A@S");
  131. }
  132.  
  133.  
  134.  
  135. /******************************************************************
  136. *   VCR::ShuttleUp - Increase shuttle speed
  137. *
  138. *   Notes:
  139. *       1.  Each time this command is received, the VCR increases
  140. *           the speed of the shuttle mode playback.  This is
  141. *           equivalent to turning the shuttle ring on the VCR
  142. *           clockwise.
  143. *
  144. *       2.  From a still frame, each command steps through 9
  145. *           speeds, varying from slow field advance to fast
  146. *           forward playback.
  147. *
  148. *       3.  Once maximum speed is attained, additional commands have
  149. *           no effect.
  150. *
  151. *       4.  Maximum command duration is 300 mSec.
  152. *
  153. *       5.  Audio is muted in all but normal playback speed, video
  154. *           is output at all speeds.
  155. *
  156. **********************************************************************/
  157. void    VCR::ShuttleUp (void)
  158. {
  159.     SendCommand ("A@O");
  160. }
  161.  
  162.  
  163.  
  164. /******************************************************************
  165. *   VCR::ShuttleDown - Decrease shuttle speed
  166. *
  167. *   Notes:
  168. *       1.  Each time this command is received, the VCR decreases
  169. *           the speed of the shuttle mode playback.  This is
  170. *           equivalent to turning the shuttle ring on the VCR
  171. *           counterclockwise.
  172. *
  173. *       2.  From a still frame, each command steps through 9
  174. *           speeds, varying from slow field advance to fast
  175. *           reverse playback.
  176. *
  177. *       3.  Once maximum speed is attained, additional commands have
  178. *           no effect.
  179. *
  180. *       4.  Maximum command duration is 300 mSec.
  181. *
  182.  
  183. *       5.  Audio is muted in all but normal playback speed, video
  184. *           is output at all speeds.
  185. *
  186. **********************************************************************/
  187. void    VCR::ShuttleDown (void)
  188. {
  189.     SendCommand ("A@P");
  190. }
  191.  
  192.  
  193.  
  194.  
  195. /******************************************************************
  196. *   VCR::ForwardShuttle - Forward shuttle
  197. *
  198. *   Parameters:
  199. *       int nSpeed - Speed in range of 0 to 8
  200. *
  201. *   Notes:
  202. *       1.  This command places the VCR into the forward shuttle
  203. *           mode at the specified speed.  When changing shuttle
  204. *           speeds, the VCR will gradually change from the
  205. *           current speed to the new speed.
  206. *
  207. *       2.  A speed of 0 will select still frame.  To freeze the
  208. *           picture faster, use ShuttleOn() instead.
  209. *
  210. *       3.  The speed argument consists of a number from 0 to 8,
  211. *           where 8 is the maximum forward play speed.  Numbers
  212. *           outside of this range are brought into range.
  213. *
  214. *       4.  It may take several seconds to change from the current
  215. *           speed to the specified speed.
  216. *
  217. *       5.  Video is output in all modes, audio is output at normal
  218. *           play speed.
  219. *
  220. **********************************************************************/
  221. void VCR::ForwardShuttle (int nSpeed)
  222. {
  223.     char    szBuffer [6];
  224.  
  225.     if (nSpeed < 0) nSpeed = 0;
  226.     if (nSpeed > 8) nSpeed = 8;
  227.     sprintf (szBuffer, "AAF%d", nSpeed);
  228.     SendCommand (szBuffer);
  229. }
  230.  
  231. /******************************************************************
  232. *   VCR::ReverseShuttle - Reverse shuttle
  233. *
  234. *   Parameters:
  235. *       int nSpeed - Speed in range of 0 to 8
  236. *
  237. *   Notes:
  238. *       1.  This command places the VCR into the reverse shuttle
  239. *           mode at the specified speed.  When changing shuttle
  240. *           speeds, the VCR will gradually change from the
  241. *           current speed to the new speed.
  242. *
  243.  
  244. *       2.  A speed of 0 will select still fr